<template>
  <van-pull-refresh class="list" v-model="loading" @refresh="onRefresh">
    <van-list v-model:loading="loadingMore" :finished="finished" finished-text="没有更多了~" @load="onLoad">
      <div class="list_item" v-for="i in dataList" @click="toDetail(i)">
        <span>{{ i.questionnaireTitle }}</span>
        <div class="item_time">{{ i.submissionTime }}</div>
      </div>
    </van-list>
  </van-pull-refresh>
</template>

<script setup>
import { queryUserQuestionnaireList } from "@/api/index";
import { ref } from "vue";
import { useRouter } from "vue-router";
let dataList = ref([]);
let router = useRouter();

// 加载更多
let loadingMore = ref(true);
let finished = ref(false);
let page = ref({
  pageNum: 1,
  pageSize: 18,
});
let loading = ref(true)
function onLoad() {
  page.value.pageNum += 1;
  getList();
}
function getList() {
  queryUserQuestionnaireList(page.value).then((res) => {

    loading.value = false;
    loadingMore.value = false;
    dataList.value.push(...res.rows);
    if (res.rows.length < page.value.pageSize) {
      finished.value = true;
    }
  });
}
getList();
function onRefresh() {
  loading.value = true;
  finished.value = false;
  loadingMore.value = true;
  dataList.value = [];
  page.value.pageNum = 1;
  getList();
}
function toDetail(i) {
  router.push("/queryInfo/" + i.id);
}
</script>

<style scoped lang="scss">
.list_item {
  height: 70px;
  border-bottom: 1px solid #ddd;
  padding: 13px 17px;
  font-size: 15px;

  .item_time {
    color: #666;
    margin-top: 10px;
  }
}
</style>
